package com.zbl.zblproject.core.config;

import com.zbl.zblproject.core.component.WechatAccountConfig;
import com.zbl.zblproject.core.entity.SnowFlake;
import me.chanjar.weixin.mp.api.WxMpConfigStorage;
import me.chanjar.weixin.mp.api.WxMpInMemoryConfigStorage;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl;
import me.chanjar.weixin.mp.bean.template.WxMpTemplateMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.server.standard.ServerEndpointExporter;

/**
 * @author youlanqiang
 * @version 1.0
 * @date 2018/12/4
 */
@Configuration
public class BeanConfig {

    @Value("${datacenter}")
    private int datacenterId;

    @Autowired
    private WechatAccountConfig accountConfig;



    @Bean
    public WxMpService wxMpService(){
        WxMpService wxMpService = new WxMpServiceImpl();
        wxMpService.setWxMpConfigStorage(wxMpConfigStorage());
        return wxMpService;
    }

    @Bean
    public WxMpConfigStorage wxMpConfigStorage(){
        WxMpInMemoryConfigStorage wxConfigProvider = new WxMpInMemoryConfigStorage();
        wxConfigProvider.setAppId(accountConfig.getAppid());
        wxConfigProvider.setSecret(accountConfig.getSecret());
        return wxConfigProvider;
    }

    @Bean
    public SnowFlake snowFlake(){
        System.out.println("datacenterId:" + datacenterId);
        return new SnowFlake(datacenterId,1);
    }
}
